package com.travel.server.manager.impl.command.project.data;

import com.travel.common.util.CommonUtil;
import com.travel.server.manager.dto.request.project.data.QueryProjectCostDetailRequest;
import com.travel.server.manager.dto.response.project.data.QueryProjectCostDetailResponse;
import com.travel.server.manager.impl.command.AbstractCommand;
import com.travel.server.manager.impl.dal.SpecialDal;
import com.travel.server.manager.model.ProjectSpecial;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author: LiZhenhui
 * @Date: 2018/11/29 12:13
 * @Desc:
 */
@Component
@Slf4j
public class QueryProjectCostDetailCommand extends AbstractCommand<QueryProjectCostDetailRequest, QueryProjectCostDetailResponse> {

    @Autowired
    private SpecialDal specialDal;

    @Override
    protected void checkInput(QueryProjectCostDetailRequest request) {
        if(request.getId() == null){
            throwInvalidParam();
        }
    }

    @Override
    public QueryProjectCostDetailResponse handle(QueryProjectCostDetailRequest request) {
        checkInput(request);
        ProjectSpecial special = specialDal.selectById(request.getId());
        int orderDiscount = specialDal.selectOrderDiscount(special.getId());
        QueryProjectCostDetailResponse response = new QueryProjectCostDetailResponse();
        response.setDiscount(CommonUtil.fenToYuan(special.getDiscount() + orderDiscount).toString());
        response.setInsurance(CommonUtil.fenToYuan(special.getInsurance()).toString());
        response.setMaterial(CommonUtil.fenToYuan(special.getMaterial()).toString());
        response.setPartner(CommonUtil.fenToYuan(special.getPartner()).toString());
        response.setTaxation(CommonUtil.fenToYuan(special.getTaxation()).toString());
        response.setTravel(CommonUtil.fenToYuan(special.getTravel()).toString());
        response.setCompensate(CommonUtil.fenToYuan(special.getCompensate()).toString());
        return response;
    }
}
